//第三层
const mongoose = require('mongoose')


//获取店铺
module.exports.get3 = async () => {
    // console.log(data)
    const data = await mongoose.model('shopModel').find();
   // console.log(data)
    return data
}

//申请店铺
module.exports.Add3 = async (data) => {
    const dataLength = await mongoose.model('shopModel').find();
    if (dataLength.length == 1) {
        const data2 = '创建失败'
        return data2
    } else if (dataLength.length == 0) {
        const data2 = await mongoose.model('shopModel').create(data.params);
        return data2
    }
}

//修改店铺
module.exports.Put3 = async (data) => {
    const _id = data.params._id
    const shopName = data.params.shopName
    const describe = data.params.describe
    const data2 = await mongoose.model('shopModel').updateOne({ _id }, { shopName, describe });
    return data2
}

// 后台自动删除
module.exports.Del3 = async function (data) {
    const data2 = await mongoose.model("shopModel").deleteOne(data.params);
    console.log(data2)
    return data2;
}
// 获取申请店铺
module.exports.getApplicationShop = async function (data) {
    return mongoose.model("shopModel").find({ bool: 0 });
}
// 同意或拒绝
module.exports.agreeAndRefuse = async function (data) {
    return await mongoose.model("shopModel").updateOne({ _id: data._id },{
        bool:Number(data.bool)
    })
}